package com.jari.lg.service.profile.event;

import com.jari.lg.domain.CrossBase;
import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.EventRtEntity;
import com.jari.lg.mapper.EventRtEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Constants;
import com.jari.lg.utils.UUIDUtils;
import com.jari.lg.utils.Utils;
import org.apache.commons.lang3.StringUtils;
import org.mockito.internal.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EventRtService {

    public int eventId = 0;

    @Autowired
    private EventRtEntityMapper eventRtEntityMapper;

    /*
    * 每小时推送50条记录
    * */
    public void makeInfo(){
        EventRtEntity entity;
        List<DevBase> devBases = BaseData.videoDetectorList;
        List<CrossBase> crossBaseList = BaseData.crossBaseList;
        for(int i = 0;  i < 50 ; i ++){
            entity = generate(devBases.get(Utils.makeRandInt(devBases.size())), crossBaseList);
            eventRtEntityMapper.insert(entity);
        }
    }


    private EventRtEntity generate(DevBase devBase,List<CrossBase> crossBaseList){
        EventRtEntity entity = new EventRtEntity();
        entity.setDevicecode(devBase.getDevicecode());
        entity.setDevicename(devBase.getDevicename());
        entity.setCarcolor(Utils.makeColor());
        entity.setCreator("SYS");
        entity.setGmtcreate(new Date());
        entity.setDatastatus(Constants.DATA_STATUS_ONE);
        entity.setEventname(Utils.makeEventName());
        entity.setDatetime(new Date());
        entity.setDescribe("发生事件");
        entity.setEventtype(Utils.makeEventType());
        entity.setLocation(devBase.getDevicename() +"抓拍到");
        entity.setEventid(eventId++);
        entity.setLat(crossBaseList.stream().filter(x -> x.getCrosscode().equals(StringUtils.isBlank(devBase.getCrosscode()) ? devBase.getKeyareagate() : devBase.getCrosscode())).findFirst().get().getCrosslat().doubleValue());
        entity.setLon(crossBaseList.stream().filter(x -> x.getCrosscode().equals(StringUtils.isBlank(devBase.getCrosscode()) ? devBase.getKeyareagate() : devBase.getCrosscode())).findFirst().get().getCrosslon().doubleValue());
        return entity;
    }
}
